package com.dongdongshop.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogAspect {

    private final Logger logger = LoggerFactory.getLogger(LogAspect.class);

    @Pointcut("execution(* com.dongdongshop.service..*.*(..))")
    public void aopLog(){

    }
    //定义前前置通知
    @Before("aopLog()")
    public void doBefore(JoinPoint joinPoint) throws Throwable{
        //获取参数
        Object[] args = joinPoint.getArgs();
        //获取正在执行的方法(切点)
        Signature signature = joinPoint.getSignature();
        logger.info("正在执行的方法 : {}","参数为:{}",signature,args);
    }
    //定义返回后通知
    @AfterReturning(value = "aopLog()",returning = "ret")
    public void doAfterReturning(Object ret) throws Throwable{
        //获取处理返回后结果
        logger.info("方法执行成功,返回的结果为：{}",ret);
    }

}
